package com.ly.demo.listener;

import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.google.common.eventbus.Subscribe;
import com.ly.demo.annotation.EventBusListener;
import com.ly.demo.vo.MailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author liuyang
 * @Date 2023/12/21 11:28
 **/
@EventBusListener
@Slf4j
@Component
public class MailListener {
    @Resource
    private MailAccount mailAccount;

    @Subscribe
    public void subscribe(MailDTO mailDTO) {
        log.info("subscribe");
        MailUtil.send(mailAccount, mailDTO.getTos(), mailDTO.getSubject(), mailDTO.getContent(), false);
    }

}
